import { View } from "../../../mvc/core/View";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { PetConfig } from "../../resource/PetConfig";
import { SWFPlayer } from "../../scene/modle/SWFPlayer";
import { ModelUtil } from "../../scene/player/info/ModelUtil";
import { ModelType } from "../../scene/modle/data/ModelType";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
type int = number;
//class PetModelPanel
    
    export  class PetModelPanel extends View
    {
        constructor()
        {
            super();
            this.init();
            this.mouseEnabled = false;
            return;
        }

        /* internal  */init(): void
        {
            this._preButton = ObjCreate.createGLoadedButton(ResFileConst.Left, -80, 15, 49, 26, this);
            this._preButton.addEventListener(flash.events.MouseEvent.CLICK, this.onNextButtonClickHandler);
            this._nextButton = ObjCreate.createGLoadedButton(ResFileConst.Right, 20, 15, 49, 26, this);
            this._nextButton.addEventListener(flash.events.MouseEvent.CLICK, this.onPreButtonClickHandler);
            return;
        }

        public updateModelByCode(arg1: int): void
        {
            var loc1=PetConfig.instance.getItemInfoByCode(arg1);
            if (this._modellayer == null) 
            {
                this._modellayer = new SWFPlayer();
                this._modellayer.loadComplete = this.onLoadCompleteHandler;
            }
            if (loc1) 
            {
                this._modellayer.load(ModelUtil.getModelSWF(loc1.pet.modelId), ModelType.Monster, loc1);
            }
            this._modellayer.currentDirection = 1;
            if (this.contains(this._modellayer) == false) 
            {
                this.addChildAt(this._modellayer, 0);
            }
            return;
        }

        public updateModelByModelId(arg1: int): void
        {
            if (this._modellayer == null) 
            {
                this._modellayer = new SWFPlayer();
                this._modellayer.loadComplete = this.onLoadCompleteHandler;
            }
            this._modellayer.load(ModelUtil.getModelSWF(arg1), ModelType.Monster, null);
            this._modellayer.currentDirection = 1;
            if (this.contains(this._modellayer) == false) 
            {
                this.addChildAt(this._modellayer, 0);
            }
            return;
        }

        public drawNow(): void
        {
            if (this._preButton) 
            {
                this._preButton.drawNow();
            }
            if (this._nextButton) 
            {
                this._nextButton.drawNow();
            }
            return;
        }

        /* internal  */onLoadCompleteHandler(arg1: SWFPlayer): void
        {
            var loc1=this._modellayer.url;
            if (loc1 != "800600.swf") 
            {
                if (loc1 != "11000098.swf") 
                {
                    if (loc1 != "12002127.swf") 
                    {
                        if (loc1 != "12002128.swf") 
                        {
                            if (loc1 != "91023702.swf") 
                            {
                                if (loc1 != "802500.swf") 
                                {
                                    if (loc1 != "91023703.swf") 
                                    {
                                        if (loc1 == "91027309.swf" || loc1 == "91027310.swf") 
                                        {
                                            this._modellayer.sceneY = 55;
                                        }
                                        else if (loc1 != "91027312.swf") 
                                        {
                                            this._modellayer.sceneY = 0;
                                        }
                                        else 
                                        {
                                            this._modellayer.sceneY = 40;
                                        }
                                    }
                                    else 
                                    {
                                        this._modellayer.sceneY = 75;
                                    }
                                }
                                else 
                                {
                                    this._modellayer.sceneY = 65;
                                }
                            }
                            else 
                            {
                                this._modellayer.sceneY = 50;
                            }
                        }
                        else 
                        {
                            this._modellayer.sceneY = 20;
                        }
                    }
                    else 
                    {
                        this._modellayer.sceneY = 30;
                    }
                }
                else 
                {
                    this._modellayer.sceneY = 35;
                }
            }
            else 
            {
                this._modellayer.sceneY = 65;
            }
            this._modellayer.updateCurrentFrame(0);
            this.dispatchEvent(new Object /* flash.events.Event */(flash.events.Event.COMPLETE));
            return;
        }

        public setTurnBtnPosition(arg1: int, arg2: int, arg3: int, arg4: int): void
        {
            if (this._preButton) 
            {
                this._preButton.move(arg1, arg2);
            }
            if (this._nextButton) 
            {
                this._nextButton.move(arg3, arg4);
            }
            return;
        }

        public showDirection(arg1: int): void
        {
            if (this._modellayer) 
            {
                this._modellayer.currentDirection = arg1;
                this._modellayer.updateFrame(this._modellayer.currentAction, this._modellayer.currentDirection);
            }
            return;
        }

        /* internal  */onPreButtonClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._modellayer) 
            {
                if (this._modellayer.currentDirection < 8) 
                {
                    this._modellayer.currentDirection = this._modellayer.currentDirection + 1;
                }
                else 
                {
                    this._modellayer.currentDirection = 1;
                }
                this._modellayer.updateFrame(this._modellayer.currentAction, this._modellayer.currentDirection);
            }
            return;
        }

        /* internal  */onNextButtonClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._modellayer) 
            {
                if (this._modellayer.currentDirection > 1) 
                {
                    --this._modellayer.currentDirection;
                }
                else 
                {
                    this._modellayer.currentDirection = 8;
                }
                this._modellayer.updateFrame(this._modellayer.currentAction, this._modellayer.currentDirection);
            }
            return;
        }

        public get isShowTurnBtn(): Boolean
        {
            return this._isShowTurnBtn;
        }

        public set isShowTurnBtn(arg1: Boolean)
        {
            this._isShowTurnBtn = arg1;
            if (this._isShowTurnBtn) 
            {
                if (!this.contains(this._preButton)) 
                {
                    this.addChild(this._preButton);
                }
                if (!this.contains(this._nextButton)) 
                {
                    this.addChild(this._nextButton);
                }
            }
            else 
            {
                if (this.contains(this._preButton)) 
                {
                    this.removeChild(this._preButton);
                }
                if (this.contains(this._nextButton)) 
                {
                    this.removeChild(this._nextButton);
                }
            }
            return;
        }

        public clean(): void
        {
            if (this._modellayer) 
            {
                this._modellayer.dispose();
            }
            return;
        }

        /* internal */ /* var */_isShowTurnBtn: Boolean;

        /* internal */ /* var */_preButton: GLoadedButton;

        /* internal */ /* var */_nextButton: GLoadedButton;

        /* internal */ /* var */_modellayer: SWFPlayer;
    }
